#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"global.h"
add(){
	int j,i;
	char key;
	CI *pa,*p;
//	head=NULL;
	pa=NULL;
	key='A';
//	printf("\nA  :Add\nB  :Back\n");
//	scanf("%c",&key);
//	if(key!='B'&&key!='A'){
//		printf("\nNo such seletcion!\n");
//		add();
	//	return(add());
/*	}
	else if(key=='B')
		menu();
	else{	*/
	while(key=='A'){
		pa=(CI *)malloc(sizeof(CI));
		printf("enter the name of contact:");
		scanf("%s",pa->name);
		getchar();
		printf("enter the telphone of %s contact:",pa->name);
		scanf("%s",pa->telphone);
		getchar();
		printf("enter the age of %s contact:",pa->name);
		scanf("%d",&pa->age);
		getchar();
		printf("enter the sex of %s contact:",pa->name);
		scanf("%c",&pa->sex);
		getchar();
		printf("enter the family phone of %s contact:",pa->name);
		scanf("%s",pa->phone);
		getchar();
		for(p=head,j=0;p!=NULL;p=p->next){
			if((strcmp(pa->name,p->name)==0)&&(strcmp(pa->phone,p->phone)==0)&&(strcmp(pa->telphone,p->telphone)==0)&&pa->age==p->age&&pa->sex==p->sex)
				j++;
		}
		if(j!=0)
			printf("\nthis contacts exits!\n");
		if(strlen(pa->telphone)!=11)
			printf("\ntel enter error!\n");
		else{
			for(i=0;i<11;i++)
				if(*(p->telphone+i)>'9'||*(p->telphone)<'0')
					printf("\ntel enter error!\n");
		}
		key='\0';
		while('S'!=key&&'A'!=key){
			printf("\nS  :Save\nA  :Abandon\n");
			scanf("%c",&key);getchar();
			if(key!='S'&&key!='A')
				printf("\nNo such seletcion!\n");
			else if('A'==key){
				free(pa);
			}
			else{
				pa->next=head;
				head=pa;
				printf("\nsave sucessfully!\n");
				filewritefor(head);
				while(key!='A'&&key!='B'){
					printf("\nA  :Add again\nB  :Back\n");
					scanf("%c",&key);getchar();
					if(key=='B')
						return(0);
				}
			}
		}		
	}
}